<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>key原理</title>
    <!-- 引用开发版 -->
    <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
    <!--
    
     -->
    <!-- 准备一个容器 -->
    <div id="root">
        <!-- 遍历数组 -->
        <button @click.once="add">添加一个老刘</button>
        <ul>
            <!-- in可以换成of -->
            <li v-for="(p,index) in persons" :key="p.id">
                {{p.name}}-{{p.age}}
                <input type="text">
            </li>
        </ul>
    </div>

    <script type="text/javascript">
        Vue.config.productionTip=false

        const vm = new Vue({
            el:'#root',
            data:{
                persons:[
                    {id:'0001', name:'张三',age:18},
                    {id:'0002', name:'李四',age:19},
                    {id:'0003', name:'王五',age:20}
                ]
            },
            methods: {
                add() {
                    const p = {id:'0004', name:'老刘',age:21}
                    this.persons.unshift(p)
                }
            }
        })
    </script>
</body>
</html